﻿// IOInputDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "IOInputDlg.h"
#include "afxdialogex.h"


// CIOInputDlg 对话框

IMPLEMENT_DYNAMIC(CIOInputDlg, CDialogEx)

CIOInputDlg::CIOInputDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_IO_INPUT, pParent)
{

}

CIOInputDlg::~CIOInputDlg()
{
}

void CIOInputDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CIOInputDlg, CDialogEx)
	ON_WM_TIMER()
	ON_WM_CONTEXTMENU()
	ON_WM_DESTROY()
	ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()

void CIOInputDlg::SetIoStatus()
{
	CButton* pCheck = nullptr;
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_0);   pCheck->SetCheck(gSystemMgr.S00);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_1);   pCheck->SetCheck(gSystemMgr.S01);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_2);   pCheck->SetCheck(gSystemMgr.S02);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_3);   pCheck->SetCheck(gSystemMgr.S03);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_4);   pCheck->SetCheck(gSystemMgr.S04);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_5);   pCheck->SetCheck(gSystemMgr.S05);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_6);   pCheck->SetCheck(gSystemMgr.S06);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_7);   pCheck->SetCheck(gSystemMgr.S07);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_8);   pCheck->SetCheck(gSystemMgr.S08);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_9);   pCheck->SetCheck(gSystemMgr.S09);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_10);  pCheck->SetCheck(gSystemMgr.S10);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_11);  pCheck->SetCheck(gSystemMgr.S11);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_12);  pCheck->SetCheck(gSystemMgr.S12);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_13);  pCheck->SetCheck(gSystemMgr.S13);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_14);  pCheck->SetCheck(gSystemMgr.S14);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_15);  pCheck->SetCheck(gSystemMgr.S15);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_16);  pCheck->SetCheck(gSystemMgr.S16);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_17);  pCheck->SetCheck(gSystemMgr.S17);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_18);  pCheck->SetCheck(gSystemMgr.S18);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_19);  pCheck->SetCheck(gSystemMgr.S19);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_20);  pCheck->SetCheck(gSystemMgr.S20);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_21);  pCheck->SetCheck(gSystemMgr.S21);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_22);  pCheck->SetCheck(gSystemMgr.S22);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_23);  pCheck->SetCheck(gSystemMgr.S23);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_24);  pCheck->SetCheck(gSystemMgr.S24);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_25);  pCheck->SetCheck(gSystemMgr.S25);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_26);  pCheck->SetCheck(gSystemMgr.S26);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_27);  pCheck->SetCheck(gSystemMgr.S27);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_28);  pCheck->SetCheck(gSystemMgr.S28);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_29);  pCheck->SetCheck(gSystemMgr.S29);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_30);  pCheck->SetCheck(gSystemMgr.S30);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_31);  pCheck->SetCheck(gSystemMgr.S31);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_32);  pCheck->SetCheck(gSystemMgr.S32);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_33);  pCheck->SetCheck(gSystemMgr.S33);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_34);  pCheck->SetCheck(gSystemMgr.S34);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_35);  pCheck->SetCheck(gSystemMgr.S35);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_36);  pCheck->SetCheck(gSystemMgr.S36);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_37);  pCheck->SetCheck(gSystemMgr.S37);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_38);  pCheck->SetCheck(gSystemMgr.S38);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_39);  pCheck->SetCheck(gSystemMgr.S39);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_40);  pCheck->SetCheck(gSystemMgr.S40);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_41);  pCheck->SetCheck(gSystemMgr.S41);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_42);  pCheck->SetCheck(gSystemMgr.S42);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_43);  pCheck->SetCheck(gSystemMgr.S43);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_44);  pCheck->SetCheck(gSystemMgr.S44);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_45);  pCheck->SetCheck(gSystemMgr.S45);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_46);  pCheck->SetCheck(gSystemMgr.S46);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_47);  pCheck->SetCheck(gSystemMgr.S47);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_48);  pCheck->SetCheck(gSystemMgr.S48);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_49);  pCheck->SetCheck(gSystemMgr.S49);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_50);  pCheck->SetCheck(gSystemMgr.S50);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_51);  pCheck->SetCheck(gSystemMgr.S51);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_52);  pCheck->SetCheck(gSystemMgr.S52);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_53);  pCheck->SetCheck(gSystemMgr.S53);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_54);  pCheck->SetCheck(gSystemMgr.S54);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_55);  pCheck->SetCheck(gSystemMgr.S55);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_56);  pCheck->SetCheck(gSystemMgr.S56);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_57);  pCheck->SetCheck(gSystemMgr.S57);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_58);  pCheck->SetCheck(gSystemMgr.S58);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_59);  pCheck->SetCheck(gSystemMgr.S59);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_60);  pCheck->SetCheck(gSystemMgr.S60);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_61);  pCheck->SetCheck(gSystemMgr.S61);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_62);  pCheck->SetCheck(gSystemMgr.S62);
	pCheck = (CButton*)GetDlgItem(IDC_CHECK_IN_63);  pCheck->SetCheck(gSystemMgr.S63);

}


BOOL CIOInputDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	SetTimer(TIMER_ID_IO_CONTROL_STATUS_IN, 50, NULL);
	ChangeIoTextIn();

	SetIoStatus();

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CIOInputDlg::OnCancel()
{
	KillTimer(TIMER_ID_IO_CONTROL_STATUS_IN);

	CDialogEx::OnCancel();
}


void CIOInputDlg::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == TIMER_ID_IO_CONTROL_STATUS_IN)
	{
		SetIoStatus();
	}

	CDialogEx::OnTimer(nIDEvent);
}

void CIOInputDlg::ChangeIoTextIn()
{
	std::vector<IO_MODULE> vIoMap;
	vIoMap = *gConfigMgr.GetIOInputSetting();
	for (int i = 0; i < 64; i++)
	{
		int cnt;
		cnt = i;
		CWnd * pStatic = nullptr;
		pStatic = (CWnd*)GetDlgItem(IDC_STATIC_IN0 + cnt);//控件编号问题
		CString cstr;
		cstr.Format(L"%d_", i);
		cstr.Append(vIoMap[i].m_cstrDescription);
		pStatic->SetWindowTextW(cstr);
	}
}
